package util;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;

import java.util.Arrays;

public class encryption {
    public static void main(String[] args) {
//        //明文
//        String min="sss";
//        //创建随机密钥
//        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
//        //构建
//        AES aes = SecureUtil.aes(key);
//        //加密
//        byte[] encrypt = aes.encrypt(min);
//        //解密
//        String s = aes.decryptStr(min);
//        System.out.println(aes.encrypt(min));
//        System.out.println(s);


        String content = "test中文";
//随机生成密钥
        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
//构建
        AES aes = SecureUtil.aes(key);
//加密
        byte[] encrypt = aes.encrypt(content);
//解密
        byte[] decrypt = aes.decrypt(encrypt);
//加密为16进制表示
        String encryptHex = aes.encryptHex(content);
//解密为字符串
        String decryptStr = aes.decryptStr(encryptHex);
        System.out.println(encryptHex);
        String s = new String(key);

        String str = StrUtil.str(key, CharsetUtil.CHARSET_UTF_8);
        System.out.println(str);
    }
    public byte[] key(){
        return SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
    }
}
